--[[/**
-- * 
  * 统计伤害次数，每次伤害额外增加爆炸伤害量万分比，爆炸基础伤害
-- *
-- */]]

---@class BuffEffect523102 : BaseBuffEffect
BuffEffect523102 = ClientFight.CreateClass("BuffEffect523102", ClientFight.BaseBuffEffect)
local t = BuffEffect523102
t.BuffEffect523102_DamageCount = "BuffEffect523102_DamageCount";
---@param fight Fight
---@param buff FighterBuff
function t:action(fight, buff, ...)
    local damageCount = buff.effectParams[t.BuffEffect523102_DamageCount] or 0;
    damageCount = damageCount + 1 ;
    buff.effectParams[t.BuffEffect523102_DamageCount] = damageCount;
    local logDamageCount = damageCount;
    SkillRoleMgr.savePathFile(
    "[" .. fight.frame .. "][EFFECT]Fighter " .. buff.target.fighterId .. " Buff"
    .. buff.modelId .. " 累加受伤害次数: " .. logDamageCount);
    return ClientFight.BaseBuffEffect.action(self, fight, buff, ...);
end

function t:remove( fight,  buff,  force, ... ) 
local parameters = {...};
local calculatorType = buff.buffBean.f_BuffEffectValue[1];
local damageType = buff.buffBean.f_BuffEffectValue[2];
local calculateAttrType = buff.buffBean.f_BuffEffectValue[3];
local bonus = buff.buffBean.f_BuffEffectValue[4] * buff.overlay;
local modifiedRatio = buff.buffBean.f_BuffEffectValue[5] * buff.overlay;
local calculator = calculatorType == 0 and buff.source or buff.target;

local result = AttackUtils.calculateEffectDamage(buff.source, buff.target, damageType, calculator, calculateAttrType, modifiedRatio, bonus);
local oldDamage = result.damage;
local damageCount =  buff.effectParams[t.BuffEffect523102_DamageCount] or 0;
local addValue = buff.buffBean.f_BuffEffectValue[6] * damageCount;
if (addValue > buff.buffBean.f_BuffEffectValue[7]) then
addValue = buff.buffBean.f_BuffEffectValue[7];
end
local addDamage = 0;
if (damageCount > 0) then
addDamage = Utils.calcRatio(result.damage,addValue);
result.damage = result.damage + addDamage;
end
DamageManager.realDamage(fight, buff.source, buff.target, buff.modelId, result, damageType);

local logAddDamage = addDamage;
local totalDamage = result.damage;
    SkillRoleMgr.savePathFile("[" .. fight.frame .. "][EFFECT]Fighter " .. buff.target.fighterId .. " Buff"
.. buff.modelId .. " 原伤害: ".. oldDamage .." 伤害次数造成的额外增加伤害: " .. logAddDamage .." 总伤害: " .. totalDamage);
    return ClientFight.BaseBuffEffect.remove(self,fight, buff, force, ...);
end
t.New()